﻿using IDAL;
using Model;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace DAL
{
    public class D_ShoppingCart : IShoppingCart
    {
        public void Add(ShoppingCart item)
        {
            CakeEntities db = new CakeEntities();
            db.ShoppingCart.Add(item);
            db.SaveChanges();
        }

        public void Delete(int id)
        {
            CakeEntities db = new CakeEntities();
            db.ShoppingCart.Remove(db.ShoppingCart.Find(id));
            db.SaveChanges();
        }

        public ShoppingCart FindById(int id)
        {
            CakeEntities db = new CakeEntities();
            return db.ShoppingCart.Find(id);
        }

        public List<ShoppingCart> GetAll()
        {
            CakeEntities db = new CakeEntities();
            return db.ShoppingCart.ToList();
        }

        public void Updata(int id, ShoppingCart item)
        {
            CakeEntities db = new CakeEntities();
            var data = db.ShoppingCart.Find(id);
            if (data!=null)
            {
                data.CustomerId = item.CustomerId;
                data.Quantity = item.Quantity;
                data.CreateDate = item.CreateDate;
                data.SizeId = item.SizeId;
                db.SaveChanges();
            }
        }
    }
}
